<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据分析 - Todo List</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            width: 95%;
            max-width: 1200px;
            min-height: 800px;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            text-align: center;
            position: relative;
        }
        
        .header h1 {
            margin-bottom: 10px;
            font-size: 2.5em;
        }
        
        .nav-btn {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 8px 16px;
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            font-size: 14px;
        }
        
        .nav-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }
        
        .nav-btn.left {
            left: 20px;
        }
        
        .nav-btn.right {
            right: 20px;
        }
        
        .content {
            padding: 30px;
        }
        
        .analytics-container {
            max-width: 900px;
            margin: 0 auto;
        }
        
        .analytics-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 2px solid #e9ecef;
        }

        .analytics-header h2 {
            color: #2c3e50;
            margin: 0;
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .action-link {
            background: linear-gradient(135deg, #28a745, #20c997);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
        }

        .action-link:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
        }
        
        .logout-btn {
            background: linear-gradient(135deg, #e74c3c, #c0392b);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
        }

        .logout-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin-bottom: 40px;
        }
        
        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 25px;
            border-radius: 15px;
            text-align: center;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .stat-number {
            font-size: 2.5em;
            font-weight: bold;
            margin-bottom: 10px;
        }
        
        .stat-label {
            font-size: 1em;
            opacity: 0.9;
        }
        
        .chart-section {
            margin-bottom: 40px;
        }
        
        .chart-container {
            background: white;
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin-bottom: 30px;
        }
        
        .chart-container h3 {
            color: #2c3e50;
            margin: 0 0 20px 0;
            text-align: center;
            font-size: 1.5em;
        }
        
        .chart-wrapper {
            position: relative;
            height: 400px;
            width: 100%;
        }
        
        .chart-wrapper canvas {
            max-height: 100% !important;
            width: 100% !important;
        }
        
        .loading {
            text-align: center;
            padding: 40px;
            color: #6c757d;
            font-size: 1.2em;
        }
        
        .error {
            color: #dc3545;
            text-align: center;
            margin-top: 20px;
            padding: 15px;
            background: #f8d7da;
            border-radius: 10px;
        }
        
        .no-data {
            text-align: center;
            padding: 40px;
            color: #6c757d;
            background: #f8f9fa;
            border-radius: 15px;
            margin: 20px 0;
        }
        
        .no-data h4 {
            margin-bottom: 10px;
            color: #495057;
        }
        
        .refresh-btn {
            background: linear-gradient(135deg, #17a2b8, #138496);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            margin-top: 20px;
        }
        
        .refresh-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(23, 162, 184, 0.3);
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="container">
            <div class="header">
                <a href="todo.html" class="nav-btn left">← 返回任务列表</a>
                <h1>📊 数据分析</h1>
                <a href="login.html" class="nav-btn right">登录页面 →</a>
            </div>
            
            <div class="content">
                <div class="analytics-container">
                    <div class="analytics-header">
                        <h2>任务完成情况分析</h2>
                        <div class="header-actions">
                            <a href="todo.html" class="action-link">
                                📝 返回任务列表
                            </a>
                            <button @click="refreshData" class="refresh-btn" :disabled="loading">
                                {{ loading ? '刷新中...' : '🔄 刷新数据' }}
                            </button>
                            <button @click="logout" class="logout-btn">退出登录</button>
                        </div>
                    </div>
                    
                    <!-- 统计卡片 -->
                    <div class="stats-grid" v-if="!loading">
                        <div class="stat-card">
                            <div class="stat-number">{{ totalTasks }}</div>
                            <div class="stat-label">总任务数</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-number">{{ completedTasks }}</div>
                            <div class="stat-label">已完成任务</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-number">{{ completionRate }}%</div>
                            <div class="stat-label">完成率</div>
                        </div>
                        <div class="stat-card">
                            <div class="stat-number">{{ totalDays }}</div>
                            <div class="stat-label">活跃天数</div>
                        </div>
                    </div>
                    
                    <div v-if="loading" class="loading">
                        正在加载数据分析...
                    </div>
                    
                    <!-- 图表区域 -->
                    <div v-if="!loading" class="chart-section">
                        <div class="chart-container" v-if="hasData">
                            <h3>每日完成任务统计</h3>
                            <div class="chart-wrapper">
                                <canvas id="dailyChart"></canvas>
                            </div>
                        </div>
                        
                        <div v-if="!hasData" class="no-data">
                            <h4>暂无数据</h4>
                            <p>您还没有完成任何任务，完成一些任务后再来查看数据分析吧！</p>
                            <a href="todo.html" class="action-link" style="margin-top: 15px; display: inline-block;">
                                去完成任务 →
                            </a>
                        </div>
                    </div>
                    
                    <div v-if="error" class="error">{{ error }}</div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="analytics.js"></script>
</body>
</html>